package com.ruoyi.web.controller.agriculture;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.agriculture.domain.po.AgOutput;
import com.ruoyi.system.agriculture.service.IAgOutputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 农业产出品Controller
 */
@RestController
@RequestMapping("/agriculture/output")
public class AgOutputController extends BaseController {
    @Autowired
    private IAgOutputService outputService;

    /**
     * 查询农业产出品列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:output:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgOutput output) {
        startPage();
        List<AgOutput> list = outputService.selectOutputList(output);
        return getDataTable(list);
    }

    /**
     * 导出农业产出品列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:output:export')")
    @Log(title = "农业产出品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AgOutput output) {
        List<AgOutput> list = outputService.selectOutputList(output);
        ExcelUtil<AgOutput> util = new ExcelUtil<>(AgOutput.class);
        return util.exportExcel(list, "农业产出品数据");
    }

    /**
     * 获取农业产出品详细信息
     */
    @PreAuthorize("@ss.hasPermi('agriculture:output:query')")
    @GetMapping(value = "/{outputId}")
    public AjaxResult getInfo(@PathVariable("outputId") Long outputId) {
        return success(outputService.getById(outputId));
    }

    /**
     * 新增农业产出品
     */
    @PreAuthorize("@ss.hasPermi('agriculture:output:add')")
    @Log(title = "农业产出品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgOutput output) {
        return toAjax(outputService.save(output));
    }

    /**
     * 修改农业产出品
     */
    @PreAuthorize("@ss.hasPermi('agriculture:output:edit')")
    @Log(title = "农业产出品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgOutput output) {
        return toAjax(outputService.updateById(output));
    }

    /**
     * 删除农业产出品
     */
    @PreAuthorize("@ss.hasPermi('agriculture:output:remove')")
    @Log(title = "农业产出品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{outputIds}")
    public AjaxResult remove(@PathVariable Long[] outputIds) {
        return toAjax(outputService.removeBatchByIds(List.of(outputIds)));
    }
} 